﻿@model ECatalog.Models.Kits.KitViewModel
@{
    Layout = "../Shared/_Layout.cshtml";
}
<div class="container">
    @using (@Html.BeginForm("SaveKit", "Kit", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        <div class="row">
            <div class="photo-editor">
                @{
        var imageUrl = "";
        if (Model != null)
        {
            imageUrl = string.Format("/Files/Organization-{0}/Kit-{1}/{2}/800x600/{3}{4}", @Model.OrganizationId, @Model.KitId, @Model.ImageUrl, @Model.ImageUrl,@Model.TypeImage);
        }
                }
                <img class="photo-block" src="@imageUrl" alt="" />
                @Html.HiddenFor(m => m.KitId)
                @Html.HiddenFor(m => m.ImageUrl)
                @Html.HiddenFor(m=>m.TypeImage)
                <input type="file" name="UploadedFile" id="UploadFile" class="form-control upload-image-button btn btn-default" value="@imageUrl" />
            </div>
            <div class="description-editor">
                <div style="width: 300px;">
                    <p>Организация</p>
                    @if (Model != null)
                    {
                        @Html.DropDownListFor(m => m.OrganizationId, new SelectList(Model.Organizations, "OrganizationId", "Name"), new { @class = "form-control" })
                    }

                    @Html.ValidationMessageFor(model => model.OrganizationId)
                </div>
            </div>
            <div class="description-editor" style="height: 270px;">
                <span class="description-text">
                    <p>Описание</p>
                </span>
                @Html.TextAreaFor(model => model.Description, new { @class = "description-block" })
                <div>
                    <label>Скидка</label>
                    @Html.TextBoxFor(model => model.Sale, new { @class = "form-control", style = "width: 100px" })
                </div>
            </div>
        </div>
        <div>
            <br/>
            <input type="submit" class="btn btn-primary" value="Сохранить" />
            @Html.ActionLink("К списку комплектов", "Index", "Kit", null, new { @class = "btn btn-link" })
        </div>
    }
    @if (Model != null && Model.KitId != 0)
    {
        <div class="row" style="margin-top: 50px;">
            <div class="panel panel-default scroll" style="height: 300px;">
                <div class="panel-heading">
                    <h3 class="panel-title">Модели</h3>
                </div>
                <div class="panel-body">
                    @foreach (var km in Model.KitModels)
                    {
                        <div class="model-editor-block">
                            @{
                        var image = string.Format("/Files/Organization-{0}/Model-{1}/{2}/320x240/{3}{4}", @km.Model.OrganizationId, @km.Model.ModelId, @km.Model.ImageUrl, @km.Model.ImageUrl,@km.Model.TypeImage);
                            }
                            <img src="@image" class="model-editor-photo" alt="" />
                            <span class="model-editor-text">@km.Model.CatNumber</span>
                            @using (@Html.BeginForm("DeleteKitModel", "Kit", new { modelId = km.Model.ModelId, kitId = Model.KitId }, FormMethod.Post))
                            {
                                <input type="submit" class="btn btn-link" value="Удалить" />
                            }
                        </div>
                    }
                    <p>
                        <a data-toggle="modal" href="#addModel" class="btn btn-primary">Добавить модель</a>
                    </p>
                </div>
            </div>
        </div>
    }
</div>

@if (Model != null && Model.KitId != 0)
{
    Html.RenderPartial("AddModel", Model);
}